﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace xxxy.DAL
{
	/// <summary>
	/// 数据访问类:mettingInfo
	/// </summary>
	public partial class mettingInfo
	{
		public mettingInfo()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("mID", "mettingInfo"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int mID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from mettingInfo");
			strSql.Append(" where mID=@mID");
			SqlParameter[] parameters = {
					new SqlParameter("@mID", SqlDbType.Int,4)
			};
			parameters[0].Value = mID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(xxxy.Model.mettingInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into mettingInfo(");
			strSql.Append("mName,mTime1,mtime2,mParticipants,mUpload,mUploadTime,mStation,mAttachment,rRemarks,maddress,msummary,mnotice,mdata)");
			strSql.Append(" values (");
			strSql.Append("@mName,@mTime1,@mtime2,@mParticipants,@mUpload,@mUploadTime,@mStation,@mAttachment,@rRemarks,@maddress,@msummary,@mnotice,@mdata)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@mName", SqlDbType.VarChar,50),
					new SqlParameter("@mTime1", SqlDbType.Date,3),
					new SqlParameter("@mtime2", SqlDbType.Date,3),
					new SqlParameter("@mParticipants", SqlDbType.NVarChar,70),
					new SqlParameter("@mUpload", SqlDbType.Int,4),
					new SqlParameter("@mUploadTime", SqlDbType.Date,3),
					new SqlParameter("@mStation", SqlDbType.Int,4),
					new SqlParameter("@mAttachment", SqlDbType.VarChar,50),
					new SqlParameter("@rRemarks", SqlDbType.VarChar,100),
					new SqlParameter("@maddress", SqlDbType.Date,3),
					new SqlParameter("@msummary", SqlDbType.NVarChar,70),
					new SqlParameter("@mnotice", SqlDbType.NVarChar,70),
					new SqlParameter("@mdata", SqlDbType.NVarChar,70)};
			parameters[0].Value = model.mName;
			parameters[1].Value = model.mTime1;
			parameters[2].Value = model.mtime2;
			parameters[3].Value = model.mParticipants;
			parameters[4].Value = model.mUpload;
			parameters[5].Value = model.mUploadTime;
			parameters[6].Value = model.mStation;
			parameters[7].Value = model.mAttachment;
			parameters[8].Value = model.rRemarks;
			parameters[9].Value = model.maddress;
			parameters[10].Value = model.msummary;
			parameters[11].Value = model.mnotice;
			parameters[12].Value = model.mdata;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(xxxy.Model.mettingInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update mettingInfo set ");
			strSql.Append("mName=@mName,");
			strSql.Append("mTime1=@mTime1,");
			strSql.Append("mtime2=@mtime2,");
			strSql.Append("mParticipants=@mParticipants,");
			strSql.Append("mUpload=@mUpload,");
			strSql.Append("mUploadTime=@mUploadTime,");
			strSql.Append("mStation=@mStation,");
			strSql.Append("mAttachment=@mAttachment,");
			strSql.Append("rRemarks=@rRemarks,");
			strSql.Append("maddress=@maddress,");
			strSql.Append("msummary=@msummary,");
			strSql.Append("mnotice=@mnotice,");
			strSql.Append("mdata=@mdata");
			strSql.Append(" where mID=@mID");
			SqlParameter[] parameters = {
					new SqlParameter("@mName", SqlDbType.VarChar,50),
					new SqlParameter("@mTime1", SqlDbType.Date,3),
					new SqlParameter("@mtime2", SqlDbType.Date,3),
					new SqlParameter("@mParticipants", SqlDbType.NVarChar,70),
					new SqlParameter("@mUpload", SqlDbType.Int,4),
					new SqlParameter("@mUploadTime", SqlDbType.Date,3),
					new SqlParameter("@mStation", SqlDbType.Int,4),
					new SqlParameter("@mAttachment", SqlDbType.VarChar,50),
					new SqlParameter("@rRemarks", SqlDbType.VarChar,100),
					new SqlParameter("@maddress", SqlDbType.Date,3),
					new SqlParameter("@msummary", SqlDbType.NVarChar,70),
					new SqlParameter("@mnotice", SqlDbType.NVarChar,70),
					new SqlParameter("@mdata", SqlDbType.NVarChar,70),
					new SqlParameter("@mID", SqlDbType.Int,4)};
			parameters[0].Value = model.mName;
			parameters[1].Value = model.mTime1;
			parameters[2].Value = model.mtime2;
			parameters[3].Value = model.mParticipants;
			parameters[4].Value = model.mUpload;
			parameters[5].Value = model.mUploadTime;
			parameters[6].Value = model.mStation;
			parameters[7].Value = model.mAttachment;
			parameters[8].Value = model.rRemarks;
			parameters[9].Value = model.maddress;
			parameters[10].Value = model.msummary;
			parameters[11].Value = model.mnotice;
			parameters[12].Value = model.mdata;
			parameters[13].Value = model.mID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int mID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from mettingInfo ");
			strSql.Append(" where mID=@mID");
			SqlParameter[] parameters = {
					new SqlParameter("@mID", SqlDbType.Int,4)
			};
			parameters[0].Value = mID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string mIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from mettingInfo ");
			strSql.Append(" where mID in ("+mIDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public xxxy.Model.mettingInfo GetModel(int mID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 mID,mName,mTime1,mtime2,mParticipants,mUpload,mUploadTime,mStation,mAttachment,rRemarks,maddress,msummary,mnotice,mdata from mettingInfo ");
			strSql.Append(" where mID=@mID");
			SqlParameter[] parameters = {
					new SqlParameter("@mID", SqlDbType.Int,4)
			};
			parameters[0].Value = mID;

			xxxy.Model.mettingInfo model=new xxxy.Model.mettingInfo();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public xxxy.Model.mettingInfo DataRowToModel(DataRow row)
		{
			xxxy.Model.mettingInfo model=new xxxy.Model.mettingInfo();
			if (row != null)
			{
				if(row["mID"]!=null && row["mID"].ToString()!="")
				{
					model.mID=int.Parse(row["mID"].ToString());
				}
				if(row["mName"]!=null)
				{
					model.mName=row["mName"].ToString();
				}
				if(row["mTime1"]!=null && row["mTime1"].ToString()!="")
				{
					model.mTime1=DateTime.Parse(row["mTime1"].ToString());
				}
				if(row["mtime2"]!=null && row["mtime2"].ToString()!="")
				{
					model.mtime2=DateTime.Parse(row["mtime2"].ToString());
				}
				if(row["mParticipants"]!=null)
				{
					model.mParticipants=row["mParticipants"].ToString();
				}
				if(row["mUpload"]!=null && row["mUpload"].ToString()!="")
				{
					model.mUpload=int.Parse(row["mUpload"].ToString());
				}
				if(row["mUploadTime"]!=null && row["mUploadTime"].ToString()!="")
				{
					model.mUploadTime=DateTime.Parse(row["mUploadTime"].ToString());
				}
				if(row["mStation"]!=null && row["mStation"].ToString()!="")
				{
					model.mStation=int.Parse(row["mStation"].ToString());
				}
				if(row["mAttachment"]!=null)
				{
					model.mAttachment=row["mAttachment"].ToString();
				}
				if(row["rRemarks"]!=null)
				{
					model.rRemarks=row["rRemarks"].ToString();
				}
				if(row["maddress"]!=null && row["maddress"].ToString()!="")
				{
					model.maddress=DateTime.Parse(row["maddress"].ToString());
				}
				if(row["msummary"]!=null)
				{
					model.msummary=row["msummary"].ToString();
				}
				if(row["mnotice"]!=null)
				{
					model.mnotice=row["mnotice"].ToString();
				}
				if(row["mdata"]!=null)
				{
					model.mdata=row["mdata"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select mID,mName,mTime1,mtime2,mParticipants,mUpload,mUploadTime,mStation,mAttachment,rRemarks,maddress,msummary,mnotice,mdata ");
			strSql.Append(" FROM mettingInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" mID,mName,mTime1,mtime2,mParticipants,mUpload,mUploadTime,mStation,mAttachment,rRemarks,maddress,msummary,mnotice,mdata ");
			strSql.Append(" FROM mettingInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM mettingInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.mID desc");
			}
			strSql.Append(")AS Row, T.*  from mettingInfo T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "mettingInfo";
			parameters[1].Value = "mID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

